/* 
 * cms，一个基于J2EE架构内容管理系统
 * Copyright © GrayRabbit Co., Ltd. All rights reserved.
 * Department:运营department
 * 更多信息请访问：
 * http://code.google.com/p/gray-rabbit-cms/
 */
package org.grayrabbit.cms.service.search.impl;

import org.grayrabbit.cms.dao.search.HotKeywordRuleDao;
import org.grayrabbit.cms.entity.HotKeywordRule;
import org.grayrabbit.cms.service.search.HotKeywordRuleService;
import org.grayrabbit.cms.vo.search.HotKeywordRuleBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import org.grayrabbit.dao.util.Page;
import org.grayrabbit.service.impl.GenericServiceImpl;
/**
 * <b>OperLog</b>的service实现类，事务加此处：





 * @version 1.0,创建时间: 2011-05-16 14:51:23  
 */
@Service
@Transactional
public class HotKeywordRuleServiceImpl extends GenericServiceImpl implements HotKeywordRuleService {
	/**
	 * 注入dao层：
	 */
	@Autowired
	@Qualifier("hotKeywordRuleDaoImpl")
	private HotKeywordRuleDao hotKeywordRuleDao;
	
	/**
	 * 此方法执行时为只读事务：
	 * @see HotKeywordRuleService#getOperLog(String)
	 */
	@Transactional(readOnly=true)
	public HotKeywordRule getHotKeywordRule(final String hotKeywordRuleId){
		HotKeywordRule hotKeywordRule = hotKeywordRuleDao.findById(hotKeywordRuleId);
		hotKeywordRuleDao.initialize(hotKeywordRule);
		return hotKeywordRule;
	}
	
	/**
	 * @see HotKeywordRuleService#delete(String)
	 */
	@Transactional
	public void delete(final HotKeywordRule hotKeywordRule) {
		hotKeywordRuleDao.makeTransient(hotKeywordRule);
	}
	
	/**
	 * @see HotKeywordRuleService#save(OperLog)
	 */
	@Transactional
	public void save(final HotKeywordRule hotKeywordRule) {
		hotKeywordRuleDao.makePersistent(hotKeywordRule);		
	}
	
	/**
	 * 此方法执行时为只读事务：
	 * @see HotKeywordRuleService#getPage(HotKeywordRuleBean)
	 */
	@Transactional(readOnly=true)
	public Page<HotKeywordRule> getPage(final HotKeywordRuleBean hotKeywordRuleBean){
		Page<HotKeywordRule> page =  new Page<HotKeywordRule>();
		page.setTotal(hotKeywordRuleDao.count(hotKeywordRuleBean));
		page.setResult(hotKeywordRuleDao.findByQc(hotKeywordRuleDao.assembly(hotKeywordRuleBean)));
		return page;
	}

	/**
	 * 此方法执行时为只读事务：
	 * @see HotKeywordRuleService#list(Page, HotKeywordRuleBean)
	 */
	public void list(Page<HotKeywordRule> page, HotKeywordRuleBean hotKeywordRuleBean) {
		if(page==null)
			return;
		if(page.isAutoCount()){
			page.setTotal(hotKeywordRuleDao.count(hotKeywordRuleBean));
		}
		page.setResult(hotKeywordRuleDao.findByPage(page,hotKeywordRuleBean));
	}
	
	/**
	 * 根据主键id列删除，批量删除OperLog
	 * @see HotKeywordRuleService#delete(String[])
	 */
	public void delete(final String[] key) {
		int i =0;
		for(String id : key){
			hotKeywordRuleDao.makeTransient(hotKeywordRuleDao.findById(id));
			i++;
			if(i==MAX_CLEAR)
				hotKeywordRuleDao.clear();
		}
		
	}
 
}